package kr.or.kead.ui.input;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.util.TreeSet;
import java.util.regex.Pattern;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;

import kr.or.kead.domain.Employee;
import kr.or.kead.service.DaoEmp;

public class ProductManagerment extends AbsInput implements ActionListener {
	JTextField txt_code, txt_name, txt_price, txt_cost;


	/*TreeSet<KeyStroke> FORWARD_TRAVERSAL = new TreeSet<KeyStroke>();
	TreeSet<KeyStroke> BACKWARD_TRAVERSAL = new TreeSet<KeyStroke>();
	FORWARD_TRAVERSAL.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
	BACKWARD_TRAVERSAL.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));*/


	public ProductManagerment(JFrame frame) {
		this.frame = frame;

		initialize();		
	}

	@Override
	protected void create_north_panel() {
		northPanel = new JPanel(new GridLayout(4, 2, 10, 10));
		JLabel code, name, price, cost;
		code = new JLabel("제품코드 : ", JLabel.CENTER);
		name = new JLabel("제 품 명 : ", JLabel.CENTER);
		price = new JLabel("판매정가 : ", JLabel.CENTER);
		cost = new JLabel("판매원가 : ", JLabel.CENTER);
		txt_code = new JTextField(4);
		txt_name = new JTextField(9);
		txt_price = new JTextField(12);
		txt_cost = new JTextField(12);
		txt_code.addKeyListener(this);
		txt_name.addKeyListener(this);
		txt_price.addKeyListener(this);
		txt_cost.addKeyListener(this);
		txt_code.setHorizontalAlignment(JTextField.CENTER);
		txt_name.setHorizontalAlignment(JTextField.CENTER);
		txt_price.setHorizontalAlignment(JTextField.CENTER);
		txt_cost.setHorizontalAlignment(JTextField.CENTER);
		northPanel.add(code);
		northPanel.add(txt_code);
		northPanel.add(name);
		northPanel.add(txt_name);
		northPanel.add(price);
		northPanel.add(txt_price);
		northPanel.add(cost);
		northPanel.add(txt_cost);

	}

	@Override
	protected void create_south_panel() {
		southPanel = new JPanel(new FlowLayout(SwingConstants.CENTER, 10, 10));
	
		btn_save = new JButton("저장");
		btn_del = new JButton("삭제");
		btn_search = new JButton("검색");
		btn_save.addActionListener(this);
		btn_del.addActionListener(this);
		btn_search.addActionListener(this);
		southPanel.add(btn_save);
		southPanel.add(btn_del);
		southPanel.add(btn_search);
	}


	@Override
	public void actionPerformed(ActionEvent e) {
		

	}

	@Override
	protected int regular_expressin() {
		if(Pattern.matches("^[a-z, A-Z]{1}[a-z,A-Z,0-9]{3}$", txt_code.getText()) == false) {
			JOptionPane.showMessageDialog(btn_save, "제품코드를 잘못 입력하셨습니다.");
			return -1;
		}else if(Pattern.matches("^[a-z, A-Z]{1,9}||[가-힣]{1,4}$", txt_name.getText()) == false) {
			JOptionPane.showMessageDialog(btn_save, "제품이름을 잘못 입력하셨습니다.");
			return -1;
		}else if(Pattern.matches("^[1-9]{1}[0-9]{1,10}$", txt_price.getText())== false) {
			JOptionPane.showMessageDialog(btn_save, "판매정가를 정수로 입력하여 주십시오.");
			return -1;
		}
		
		return 0;
	}

	@Override
	protected void clear_component() {
		// TODO Auto-generated method stub

	}







}
